﻿using System.ComponentModel;
using System.Web;
using System.Web.Mvc;
using xTeam.HengLe.DataAccess;
using xTeam.HengLe.Entity;
using System.Collections.Generic;
using System.Web.Routing;

namespace xTeam.HengLe.Controller.Manage {
    public class GuestBookController : BaseController {
        protected override void Initialize(RequestContext requestContext) {
            base.Initialize(requestContext);
            this.SiteMapPathAdd(ViewsResources.SiteMapPath.GuestBook, Url.Action("Index"));
        }
        /// <summary>
        /// 留言簿主页
        /// </summary>
        public ActionResult Index(int productId = 0) {
            return RedirectToAction("List", new { productId = productId });
        }
        /// <summary>
        /// 留言簿主页
        /// </summary>
        public ActionResult List(int productId = 0) {
            ViewData["ProductId"] = TempData["ProductId"] = productId;
            this.SiteMapPathAdd(ViewsResources.SiteMapPath.List);
            GuestBookViewModel viewModel = new GuestBookViewModel();
            viewModel.GuestBookList = _guestBookDataAccess.Search(productId);
            return View(viewModel);
        }
        // 编辑
        [HttpPost]
        public ActionResult Edit() {
            EGuestBook egb = _guestBookDataAccess.GetGuestBookById(int.Parse(Request.Form["gbid"]));
            egb.ReContent = Server.HtmlEncode(Request.Form["tbrecontent"]);

            _guestBookDataAccess.Edit(egb);
            return RedirectToAction("List", new { productId = TempData["ProductId"] });
        }

        [HttpPost]
        public ActionResult Replay(int gbid) {
            return this.Content((_guestBookDataAccess.GetGuestBookById(gbid) ?? new EGuestBook()).ReContent);
        }

        public ActionResult Delete(int gbid) {
            _guestBookDataAccess.Delete(gbid);
            return this.RedirectToAction("Index", new { productId = TempData["ProductId"] });
        }
    }
}
